/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmBusqProcEmpadr.java
 *
 * Created on 19-may-2011, 15:20:40
 */
package verins.GUI;

import java.util.Iterator;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import verins.BO.ProcesoEmpadronamientoBO;
import verins.GUI.frmProcesoEmpadronamiento;
import verins.beans.Procesoempadronamiento;

/**
 *
 * @author hectdx
 */
public class frmBusqProcEmpadr extends javax.swing.JFrame {

    List<Procesoempadronamiento> lstProcesos=null;
    /** Creates new form frmBusqProcEmpadr */
    public frmBusqProcEmpadr() {
        initComponents();
        verins.Utils.Comunes.centrarVentana(this);
        llenarTabla();
    }

    
    public void llenarTabla(){
        verins.Utils.Comunes.limpiarTabla(tblProcesos);
        lstProcesos = ProcesoEmpadronamientoBO.findAll();
        DefaultTableModel dtm=(DefaultTableModel)tblProcesos.getModel();
        if (lstProcesos!=null&& lstProcesos.size()>0){
            Iterator it=lstProcesos.iterator();
            while(it.hasNext()){
                Procesoempadronamiento p=(Procesoempadronamiento)it.next();
                Object fila[]=new Object[] {p.getDescripcion(), p.getIdestadoprocesoempadronamiento().getDescripcion()};
                dtm.addRow(fila);
            }
        }
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblProcesos = new javax.swing.JTable();
        btnCerrar = new javax.swing.JButton();
        btnDetalle = new javax.swing.JButton();
        btnNuevo = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Búsqueda proceso empadronamiento");
        setResizable(false);

        jLabel1.setText("PROCESO ELECTORAL");

        tblProcesos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Proceso empadronamiento", "Estado"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblProcesos);

        btnCerrar.setText("Cerrar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        btnDetalle.setText("Ver Detalle");
        btnDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetalleActionPerformed(evt);
            }
        });

        btnNuevo.setText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        btnEditar.setText("Editar");
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(btnNuevo)
                            .addGap(18, 18, 18)
                            .addComponent(btnEditar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnDetalle)
                            .addGap(138, 138, 138)
                            .addComponent(btnCerrar))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 511, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCerrar)
                    .addComponent(btnNuevo)
                    .addComponent(btnDetalle)
                    .addComponent(btnEditar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        // TODO add your handling code here:
        new frmProcesoEmpadronamiento(null,this).setVisible(true);
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void btnDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetalleActionPerformed
        // TODO add your handling code here:
        if (lstProcesos!=null){
            int fila=tblProcesos.getSelectedRow();
            if (fila>=0){
                 frmProcesoEmpadronamiento frm=new  frmProcesoEmpadronamiento(lstProcesos.get(fila),this);
                frm.setVisible(true);
                frm.habilitarCampos();
                frm.mostrarBotonGuardar(false);
                frm.setearBotonSalirCancelar("Salir");
            }
        }
    }//GEN-LAST:event_btnDetalleActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        // TODO add your handling code here:
         if (lstProcesos!=null){
            int fila=tblProcesos.getSelectedRow();
            if (fila>=0){
                
                frmProcesoEmpadronamiento frm=new  frmProcesoEmpadronamiento(lstProcesos.get(fila),this);
                frm.setVisible(true);
                frm.habilitarCampos();
            }
        }
        
    }//GEN-LAST:event_btnEditarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmBusqProcEmpadr().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnDetalle;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblProcesos;
    // End of variables declaration//GEN-END:variables
}
